﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product.Base;
using ERP_RORZE_PERMISSION.Base;

namespace ERP_RORZE_PRODUCT.Product.BasicList
{
    public partial class ctrlJig : DevExpress.XtraEditors.XtraUserControl
    {
        ClsBasicListDAO clsBasiclistDAO = new ClsBasicListDAO();
        DataTable dt;
        Jig b = new Jig();
        private LogUtils log;

        public ctrlJig()
        {
            InitializeComponent();
            log = new LogUtils();
        }

        void Reload(object sender, EventArgs e)
        {
            dt = clsBasiclistDAO.GetAlJig();
            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();
        }
        private void btnReload_Click(object sender, EventArgs e)
        {
            Reload(sender,e);
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            b.JigType = gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"JigType").ToString();
            clsBasiclistDAO.DeleteJig(b);

            //write Log
            log.Table = LogConstant.Table.Product.Jigs;
            log.Task = LogConstant.Task.Delete;
            log.Description = b.JigType;
            log.WriteLog();

            Reload(sender, e);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            frm_JigAdd frmAdd = new frm_JigAdd();
            frmAdd.Reload += new EventHandler(Reload);
            frmAdd.ShowDialog();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                frm_JigEdit frmEdit = new frm_JigEdit();
                frmEdit.Reload += new EventHandler(Reload);
                frmEdit.JigType = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "JigType").ToString();
                frmEdit.JigName = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "JigName").ToString();
                frmEdit.ShowDialog();
            }
            catch
            {
            }
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            btnAdd_Click(sender, e);
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            btnEdit_Click(sender, e);
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            btnDelete_Click(sender, e);
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            clsConstantsFuction.ExportToExcel(gridView1, 1, true);
        }

        private void ctrlJig_Load(object sender, EventArgs e)
        {
            Reload(sender, e);
        }
    }
}
